layui.use('laydate', function(){
    var laydate = layui.laydate;
    
    var end = laydate.render({
    	elem: '#timeEnd', //指定元素
    	done:function(value,date){
    		start.config.max={
   				year:date.year,
   				month:date.month-1,
   				date:date.date
    		}
    	}
    })
    
    var start = laydate.render({
    	elem: '#timaStart', //指定元素
    	done:function(value,date){
    		end.config.min={
   				year:date.year,
   				month:date.month-1,
   				date:date.date
    		}
    	}
    })
    
  //执行一个laydate实例
    laydate.render({
      elem: '#timaStart' //指定元素
    });

    //执行一个laydate实例
    laydate.render({
      elem: '#timeEnd' //指定元素
    });
    
  });  

layui.use('table', function(){
  var table = layui.table;
 
  //监听表格复选框选择
  table.on('checkbox(demo)', function(obj){
    console.log(obj)
  });
  //表单重载
  var $ = layui.$, active = {
		    reload: function(){
		      var demoReload = $('#demoReload');
		      var purDateStart=$('#timaStart');
		      var purDateEnd=$('#timeEnd');
		      //执行重载
		      table.reload('idTest', {
		        page: {
		          curr: 1 //重新从第 1 页开始
		        }
		        ,where: {
		        	companyName:demoReload.val(),
		            purDateStart: purDateStart.val(),
		            purDateEnd: purDateEnd.val(),
		            purchaseId: getParameter("id")
		        }
		      });
		    }
		  };
  
  
//监听工具条
  table.on('tool(demo)', function(obj){
    var da = obj.data;
    //审核
    if(obj.event === 'audit'){
    	layer.open({
  		  type: 2, //设置为iframe
  		  area: ['40%', '55%'],
  		  content: ['../../pages/companyLeague/audit.html?id='+da.companyId+'', 'no'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
  	  }); 
    //查看详情
    } else if(obj.event === 'detail'){
    	layer.open({
      	  title: "审核记录",
    		  type: 2, //设置为iframe
    		  shift:1,//弹出框动画效果
    		  area: ['66%', '45%'],
    		  content: ['../../pages/companyLeague/leagueAuditDetail.html?id='+da.companyId, 'no'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
    		 
    	  }); 
    //修改
    } else if(obj.event === 'update'){
    	layer.open({
    		  type: 2, //设置为iframe
    		  area: ['400px', '500px'],
    		  content: ['insertOrUpdate.html', 'on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
    		  ,success: function(layero, index){
    			var url="../../listenCompany/selectCompany.action";
    	    	var data={"companyId":da.companyId};
    	    	$.post(url,data,function(mes){
    	    	var body = layer.getChildFrame('body', index);
  				var iframe = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
  				$.each(mes,function(i,item){
  					iframe.$("#companyId").val(item.companyId);
  					iframe.$("#buId").val(item.buId);
  					iframe.$("#buName").val(item.buName);
  					iframe.$("#buPwd").val(item.buPwd);
  	  				iframe.$("#buPhone").val(item.buPhone);
  	  			    iframe.$("#companyName").val(item.companyName);
	  				iframe.$("#companyAddress").val(item.companyAddress);
  				})
    	    	
  				// alert(mes.newPath);
  				//调用子页面渲染的方法 刷新
  				/*iframe.load();*/
    	    	},"json");
    		  }
    	  }); 
      }
  });
  active['reload'] ? active['reload'].call(this) : '';
  $('.demoTable .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
});
/**
 * 从地址栏传值的代码
 * @param param
 * @returns
 */
function getParameter(param){
	var query = window.location.search;
	var iLen = param.length;
	var iStart = query.indexOf(param);
	if (iStart == -1)
		return "";
	iStart += iLen + 1;
	var iEnd = query.indexOf("&", iStart);
	if (iEnd == -1)
		return query.substring(iStart);
	return query.substring(iStart, iEnd);
}